package com.googlecode.recycled.lang.jse.api.io;

import com.google.common.collect.Lists;
import com.google.common.io.PatternFilenameFilter;

import java.io.FileFilter;
import java.util.List;

public class FileFilterBuilder {

    protected final ChainedFileFilter.Matcher matcher;

    protected List<FileFilter> filters = Lists.newLinkedList();

    protected FileFilterBuilder(ChainedFileFilter.Matcher matcher) {
        this.matcher = matcher;
    }

    public static FileFilterBuilder all() {
        return new FileFilterBuilder(ChainedFileFilter.Matcher.ALL);
    }

    public static FileFilterBuilder any() {
        return new FileFilterBuilder(ChainedFileFilter.Matcher.ANY);
    }

    public FileFilter build() {
        return new ChainedFileFilter(matcher, filters);
    }

    public FileFilterBuilder nameMatches(String pattern) {
        filters.add(new FileFilterAdapter(new PatternFilenameFilter(pattern)));
        return this;
    }

    public FileFilterBuilder isDictionary() {
        filters.add(FilesExt.FILE_FILTER_DICTIONARY);
        return this;
    }

    public FileFilterBuilder isFile() {
        filters.add(FilesExt.FILE_FILTER_FILE);
        return this;
    }

    public FileFilterBuilder isNonEmpty() {
        filters.add(FilesExt.FILE_FILTER_NON_EMPTY);
        return this;
    }


}
